package org.rcy.framework.pay.config.ali;

import com.egzosn.pay.ali.api.AliPayConfigStorage;
import com.egzosn.pay.ali.api.AliPayService;
import com.egzosn.pay.common.http.HttpConfigStorage;
import org.rcy.framework.pay.config.PayHttpConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 吴康桥
 * @Description
 * @date 2023/8/28 10:19
 */

@EnableConfigurationProperties({AliPayConfigProperties.class, PayHttpConfigProperties.class})
@Configuration
public class AliPayAutoConfiguration {

	@Autowired
	private AliPayConfigProperties aliPayConfigProperties;
	@Autowired
	private PayHttpConfigProperties httpConfigProperties;

	@Bean
	public AliPayServiceWrapper aliPayServiceWrapper() {
		AliPayConfigStorage aliPayConfigStorage = new AliPayConfigStorage();
		aliPayConfigStorage.setPayType("aliPay");
		aliPayConfigStorage.setPid(aliPayConfigProperties.getPid());
		aliPayConfigStorage.setAppid(aliPayConfigProperties.getAppId());
		aliPayConfigStorage.setTest(aliPayConfigProperties.getTest());
		aliPayConfigStorage.setSeller(aliPayConfigProperties.getSeller());
		aliPayConfigStorage.setAppAuthToken(aliPayConfigProperties.getAppAuthToken());
		aliPayConfigStorage.setSignType(aliPayConfigProperties.getSignType());
		aliPayConfigStorage.setInputCharset(aliPayConfigProperties.getInputCharset());
		aliPayConfigStorage.setKeyPublic(aliPayConfigProperties.getKeyPublic());
		aliPayConfigStorage.setKeyPrivate(aliPayConfigProperties.getKeyPrivate());
		//请求连接池配置
		HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
		//最大连接数
		httpConfigStorage.setMaxTotal(httpConfigProperties.getMaxTotal());
		//默认的每个路由的最大连接数
		httpConfigStorage.setDefaultMaxPerRoute(httpConfigProperties.getDefaultMaxPerRoute());
		return new AliPayServiceWrapper(aliPayConfigStorage,httpConfigStorage);
	}
}
